/**
 * 389. 找不同
 * https://leetcode-cn.com/problems/find-the-difference/
 */
public class Solutions_389 {
    public static void main(String[] args) {
//        String s = "abcd", t = "abcde";  // output: "e"
//        String s = "", t = "y";  // output: "y"
//        String s = "a", t = "aa";  // output: "a"
        String s = "ae", t = "aea";  // output: "a"

        char result = findTheDifference(s, t);
        System.out.println(result);
    }

    // 异或解法
    public static char findTheDifference(String s, String t) {
        // 任何数与 0 进行异或，结果都是数本身
        int c = 0;
        char[] arr1 = s.toCharArray();
        char[] arr2 = t.toCharArray();
        // a 与两个 b 异或后，结果还是 a
        // a 与 a 异或后，结果是 0
        for (char h : arr1) {
            c = c ^ h;
        }
        for (char h : arr2) {
            c = c ^ h;
        }
        return (char) c;
    }
}
